<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/1/3-15:47
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\admin\controller;


    use app\admin\model\Logs;
    use app\admin\service\MenuService;
    use app\admin\model\Menus;

    use Jrk\Trees;
    use think\Exception;
    use think\File;
    use think\Request;

    class Menu extends AdminBase
    {

        public function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub
            $this->service=new MenuService();
            $this->model=new Menus();
            $this->del="菜单";
        }



        /**
         * @param Request $request
         * @return mixed
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/1/9
         * @name: addMenu
         * @describe:添加编辑菜单
         */
        public function addMenu(){
            if (IS_POST){
                $data = $this->request->post();

                if (isset($data['id'])){
                    parent::addLog("菜单添加修改操作","修改菜单：".$data['title']);
                }else{
                    parent::addLog("菜单添加修改操作","新增菜单：".$data['title']);
                }
                return $this->model->addAndEdit($data);
            }
            $tree = Trees::toFormatTree($this->service->menuList());//获取菜单列表
            //dump($tree);die;
            $pid = $this->request->param("id/d");//父id

            $this->assign(compact("pid", "tree"));

            return $this->fetch();

        }



        /**
         * @return mixed
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/1/9
         * @name: editMenu
         * @describe:编辑
         */
        public function editMenu(){
            $tree = Trees::toFormatTree($this->service->menuList());//获取菜单列表
            //dump($tree);die;
            $id   = $this->request->param("id/d");//父id

            $info = $this->service->getOne(['id'=>$id]);
            $pid  = $info['pid'];


            $this->assign(compact("pid", "tree", "info"));
            return $this->fetch();
        }




    }